#include <stdio.h>
#include "lv_conf.h"
#include <sys/time.h>
#include <sdl/sdl.h>
#include "lvgl/lvgl.h"
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include <sys/time.h>
#include <unistd.h>
#include <pthread.h>
#include <ui.h>
#include <demos/lv_demos.h>
#include "main.h"
#include <math.h>
#include <time.h>

#define DISP_BUF_SIZE (800 * 480 * 4)
int yb_water_temp = 0;

int current_speed_angle = 0; // 当前指针角度

static int current_rev_angle = 0; // 当前角度
static int last_revspeed = 0;     // 上次转速度值

static bool is_animating = false;     // 动画状态标志
static bool is_rev_animating = false; // 动画状态标志

// 冷却液温度指针全局变量
static int current_coolant_angle = -450;  // 当前角度
static bool is_coolant_animating = false; // 动画状态
static int last_coolant_temp = 0;         // 上次温度值

// 油耗指针全局变量
static float current_fuel_angle = FUEL_MIN_ANGLE;          // 当前角度
static float last_fuel_consumption = FUEL_CONSUMPTION_MAX; // 上次油耗值
static bool is_fuel_animating = false;                     // 动画状态标志
static int remaining_steps = 0;                            // 剩余动画步数
static float angle_step = 0;                               // 单步角度变化量
static float target_consumption = 0;                       // 目标油耗值
float new_xingshiyouhao = 1.0f;                            // 初始化为最高油耗值
float yb_xingshiyouhao = 1.0f;                             // 初始化为最高油耗值

// 左转向灯状态变量
bool left_turn_signal_on = false;
static bool is_left_signal_animating = false;

// 右转向灯状态变量
bool right_turn_signal_on = false;
bool is_right_signal_animating = false;

// 双闪状态变量
bool hazard_lights_on = false;

// 动画参数配置
#define BASE_ANIM_TIME 300     // 基础动画时间(ms)
#define ANGLE_TIME_RATIO 2     // 每度增加的动画时间(ms/度)
#define MIN_ANIM_TIME 300      // 最小动画时间(ms)
#define MAX_ANIM_TIME 1200     // 最大动画时间(ms)
#define DIRECT_SET_THRESHOLD 5 // 直接设置的角度阈值(度)

// 转速度指针参数配置
#define REV_BASE_ANGLE 146     // 每500转对应的角度(146度)
#define REV_BASE_TIME 500      // 基础动画时间(ms)
#define REV_MIN_ANGLE_CHANGE 5 // 最小角度变化(直接设置)

// 冷却液温度指针参数配置
#define COOLANT_MIN_ANGLE -570     // 最小角度(对应最高温度)
#define COOLANT_MAX_ANGLE -450     // 最大角度(对应最低温度)
#define COOLANT_TEMP_RANGE 120     // 温度范围0-120℃
#define COOLANT_ANGLE_RANGE 500    // 角度范围120度(-570 - (-450))
#define COOLANT_BASE_TIME 500      // 基础动画时间(ms)
#define COOLANT_MIN_ANGLE_CHANGE 2 // 最小角度变化(直接设置)

// 油耗指针参数配置
#define FUEL_BASE_TIME 600         // 基础动画时间(ms)
#define FUEL_MIN_ANGLE_CHANGE 2.0f // 最小角度变化(直接设置)

// 动画完成回调函数
static void anim_ready_cb(lv_anim_t *a)
{
    is_animating = false;
}

// 动画完成回调
static void rev_anim_ready_cb(lv_anim_t *a)
{
    is_rev_animating = false;
}

// 动画完成回调
static void coolant_anim_ready_cb(lv_anim_t *a)
{
    is_coolant_animating = false;
}

// 单步动画完成回调
static void fuel_anim_step_cb(lv_anim_t *a)
{
    // 更新当前角度
    current_fuel_angle = lv_img_get_angle(ui_zhizhen4);

    // 更新UI显示
    lv_img_set_angle(ui_zhizhen4, (int16_t)current_fuel_angle);

    // 如果还有剩余步骤，继续动画
    if (--remaining_steps > 0)
    {
        float next_angle = current_fuel_angle + angle_step;

        // 创建下一步动画
        lv_anim_t next_a;
        lv_anim_init(&next_a);
        lv_anim_set_var(&next_a, ui_zhizhen4);
        lv_anim_set_exec_cb(&next_a, (lv_anim_exec_xcb_t)lv_img_set_angle);
        lv_anim_set_values(&next_a, (int16_t)current_fuel_angle, (int16_t)next_angle);
        lv_anim_set_time(&next_a, STEP_ANIM_TIME);
        lv_anim_set_ready_cb(&next_a, fuel_anim_step_cb);
        lv_anim_start(&next_a);
    }
    else
    {
        // 所有步骤完成，更新最终状态
        is_fuel_animating = false;
        last_fuel_consumption = target_consumption;
    }
}

// 速度指针动画控制函数
void update_speed_pointer(int new_speed)
{
    // 计算目标角度(0-2400度对应0-240km/h)
    int target_angle = new_speed * 9.6;

    // 如果正在执行动画，则停止当前动画
    if (is_animating)
    {
        lv_anim_del(ui_zhizhen1, NULL);
    }

    // 如果角度变化很小，直接设置而不使用动画
    if (abs(target_angle - current_speed_angle) < DIRECT_SET_THRESHOLD)
    {
        lv_img_set_angle(ui_zhizhen1, target_angle);
        current_speed_angle = target_angle;
        return;
    }

    // 创建动画对象
    lv_anim_t a;
    lv_anim_init(&a);

    // 设置动画参数
    lv_anim_set_var(&a, ui_zhizhen1);
    lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_img_set_angle);
    lv_anim_set_values(&a, current_speed_angle, target_angle);

    // 动态计算动画时间
    int angle_diff = abs(target_angle - current_speed_angle);
    uint16_t anim_time = BASE_ANIM_TIME + angle_diff * ANGLE_TIME_RATIO;
    anim_time = LV_CLAMP(MIN_ANIM_TIME, anim_time, MAX_ANIM_TIME);

    lv_anim_set_time(&a, anim_time);

    // 使用缓出曲线（启动快，结束慢）
    lv_anim_set_path_cb(&a, lv_anim_path_ease_out);

    // 设置动画完成回调
    lv_anim_set_ready_cb(&a, anim_ready_cb);

    // 启动动画
    lv_anim_start(&a);
    is_animating = true;

    // 更新当前角度
    current_speed_angle = target_angle;
}

// 转速度指针更新函数
void update_revspeed_pointer(int new_revspeed)
{
    // 计算目标角度 (每500转=146度)
    int target_angle = (new_revspeed / 500) * REV_BASE_ANGLE;

    // 限制最大角度(假设最大8000转)
    target_angle = LV_CLAMP(0, target_angle, (8000 / 500) * REV_BASE_ANGLE);

    // 如果正在执行动画，则停止当前动画
    if (is_rev_animating)
    {
        lv_anim_del(ui_zhizhen2, NULL);
    }

    // 小角度变化直接设置
    if (abs(target_angle - current_rev_angle) < REV_MIN_ANGLE_CHANGE)
    {
        lv_img_set_angle(ui_zhizhen2, target_angle);
        current_rev_angle = target_angle;
        last_revspeed = new_revspeed;
        return;
    }

    // 确定旋转方向
    int direction = (new_revspeed > last_revspeed) ? 1 : -1;

    // 创建动画对象
    lv_anim_t a;
    lv_anim_init(&a);

    // 设置动画参数
    lv_anim_set_var(&a, ui_zhizhen2);
    lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_img_set_angle);

    // 根据方向设置动画值
    if (direction > 0)
    {
        // 加速 - 顺时针
        lv_anim_set_values(&a, current_rev_angle, target_angle);
    }
    else
    {
        // 减速 - 逆时针
        lv_anim_set_values(&a, current_rev_angle, target_angle);
    }

    // 动态计算动画时间
    int angle_diff = abs(target_angle - current_rev_angle);
    uint16_t anim_time = REV_BASE_TIME * angle_diff / REV_BASE_ANGLE;
    anim_time = LV_CLAMP(300, anim_time, 1500); // 限制在300-1500ms之间

    lv_anim_set_time(&a, anim_time);

    // 使用缓动曲线
    lv_anim_set_path_cb(&a, direction > 0 ? lv_anim_path_ease_out : lv_anim_path_ease_in);

    // 设置动画完成回调
    lv_anim_set_ready_cb(&a, rev_anim_ready_cb);

    // 启动动画
    lv_anim_start(&a);
    is_rev_animating = true;

    // 更新状态
    current_rev_angle = target_angle;
    last_revspeed = new_revspeed;
}

// 冷却液温度指针更新函数
void update_coolant_temp(int new_temp)
{
    // 确保温度在0-120℃范围内
    new_temp = LV_CLAMP(0, new_temp, COOLANT_TEMP_RANGE);

    // 计算目标角度 (线性映射: 0℃=-450°, 120℃=-570°)
    int target_angle = COOLANT_MAX_ANGLE - (new_temp * COOLANT_ANGLE_RANGE / COOLANT_TEMP_RANGE);

    // 如果正在执行动画，则停止当前动画
    if (is_coolant_animating)
    {
        lv_anim_del(ui_zhizhen3, NULL);
    }

    // 小角度变化直接设置
    if (abs(target_angle - current_coolant_angle) < COOLANT_MIN_ANGLE_CHANGE)
    {
        lv_img_set_angle(ui_zhizhen3, target_angle);
        current_coolant_angle = target_angle;
        last_coolant_temp = new_temp;
        return;
    }

    // 确定旋转方向(温度升高时逆时针，降低时顺时针)
    bool is_increasing = (new_temp > last_coolant_temp);

    // 创建动画对象
    lv_anim_t a;
    lv_anim_init(&a);

    // 设置动画参数
    lv_anim_set_var(&a, ui_zhizhen3);
    lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_img_set_angle);
    lv_anim_set_values(&a, current_coolant_angle, target_angle);

    // 动态计算动画时间(基于角度差)
    int angle_diff = abs(target_angle - current_coolant_angle);
    uint16_t anim_time = COOLANT_BASE_TIME * angle_diff / COOLANT_ANGLE_RANGE;
    anim_time = LV_CLAMP(300, anim_time, 1500); // 限制在300-1500ms之间

    lv_anim_set_time(&a, anim_time);

    // 使用不同的缓动曲线增强效果
    lv_anim_set_path_cb(&a, is_increasing ? lv_anim_path_ease_out : lv_anim_path_ease_in);

    // 设置动画完成回调
    lv_anim_set_ready_cb(&a, coolant_anim_ready_cb);

    // 启动动画
    lv_anim_start(&a);
    is_coolant_animating = true;

    // 更新状态
    current_coolant_angle = target_angle;
    last_coolant_temp = new_temp;
}

// 初始化油耗指针
void init_fuel_pointer()
{
    // 设置初始角度为最高油耗位置
    current_fuel_angle = FUEL_MIN_ANGLE;
    lv_img_set_angle(ui_zhizhen4, (int16_t)current_fuel_angle);
    lv_img_set_pivot(ui_zhizhen4, 114, 21); // 设置旋转枢轴点

    // 初始化状态
    last_fuel_consumption = FUEL_CONSUMPTION_MAX;
    is_fuel_animating = false;
}

// 油耗指针更新函数
void update_fuel_consumption(float new_consumption)
{
    // 确保油耗在有效范围内
    new_consumption = LV_CLAMP(FUEL_CONSUMPTION_MIN, new_consumption, FUEL_CONSUMPTION_MAX);

    // 如果正在执行动画，则停止当前动画
    if (is_fuel_animating)
    {
        lv_anim_del(ui_zhizhen4, NULL);
    }

    // 计算油耗变化量（以0.1为单位）
    float consumption_diff = (new_consumption - last_fuel_consumption) * 10.0f;

    // 确定旋转方向（油耗减少顺时针，增加逆时针）
    float direction = (new_consumption < last_fuel_consumption) ? 1.0f : -1.0f;

    // 计算需要执行的步数（每0.1油耗为一步）
    remaining_steps = (int)fabs(consumption_diff);

    // 计算单步角度变化量（带方向）
    angle_step = ANGLE_PER_STEP * direction;

    // 保存目标值
    target_consumption = new_consumption;

    // 启动第一步动画
    float next_angle = current_fuel_angle + angle_step;

    lv_anim_t a;
    lv_anim_init(&a);
    lv_anim_set_var(&a, ui_zhizhen4);
    lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_img_set_angle);
    lv_anim_set_values(&a, (int16_t)current_fuel_angle, (int16_t)next_angle);
    lv_anim_set_time(&a, STEP_ANIM_TIME);
    lv_anim_set_ready_cb(&a, fuel_anim_step_cb);
    lv_anim_start(&a);

    // 更新动画状态
    is_fuel_animating = true;
}

// 左转向灯动画回调
static void left_signal_anim_cb(lv_anim_t *a)
{
    static bool toggle_state = false;
    
    // 只有当左转向灯或双闪开启时才继续动画
    if (left_turn_signal_on || hazard_lights_on)
    {
        // 交替显示/隐藏转向灯图标
        if (lv_obj_is_visible(ui_zxdon2))
        {
            lv_obj_add_flag(ui_zxdon2, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_zxdoff1, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_zxdoff1, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_zxdon2, LV_OBJ_FLAG_HIDDEN);
        }

        // 继续下一次动画
        lv_anim_t anim;
        lv_anim_init(&anim);
        lv_anim_set_var(&anim, ui_zxdon2);
        lv_anim_set_time(&anim, 500); // 500ms闪烁间隔
        lv_anim_set_ready_cb(&anim, left_signal_anim_cb);
        lv_anim_start(&anim);
    }
    else
    {
        // 关闭转向灯
        lv_obj_add_flag(ui_zxdon2, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_zxdoff1, LV_OBJ_FLAG_HIDDEN);
        is_left_signal_animating = false;
    }
}

// 左转向灯开关控制
void toggle_left_turn_signal(bool enable)
{
    // 如果开启左转向灯且双闪正在开启，先关闭双闪
    if (enable && hazard_lights_on) {
        toggle_hazard_lights(false);
    }

    // 如果是由双闪触发的，不检查当前状态
    if (!hazard_lights_on && enable == left_turn_signal_on)
        return;

    left_turn_signal_on = enable;

    if (enable && !is_left_signal_animating)
    {
        is_left_signal_animating = true;

        // 初始状态：点亮转向灯
        lv_obj_add_flag(ui_zxdoff1, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_zxdon2, LV_OBJ_FLAG_HIDDEN);

        lv_anim_t anim;
        lv_anim_init(&anim);
        lv_anim_set_var(&anim, ui_zxdon2);
        lv_anim_set_time(&anim, 500);
        lv_anim_set_ready_cb(&anim, left_signal_anim_cb);
        lv_anim_start(&anim);
    }
    else if (!enable)
    {
        lv_obj_add_flag(ui_zxdon2, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_zxdoff1, LV_OBJ_FLAG_HIDDEN);
        is_left_signal_animating = false;
    }
}

// 右转向灯动画回调
static void right_signal_anim_cb(lv_anim_t *a)
{
   // 只有当右转向灯或双闪开启时才继续动画
    if (right_turn_signal_on || hazard_lights_on)
    {
        // 交替显示/隐藏右转向灯图标
        if (lv_obj_is_visible(ui_yxdon2))
        {
            lv_obj_add_flag(ui_yxdon2, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_yxdoff1, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_yxdoff1, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_yxdon2, LV_OBJ_FLAG_HIDDEN);
        }

        // 继续下一次动画
        lv_anim_t anim;
        lv_anim_init(&anim);
        lv_anim_set_var(&anim, ui_yxdon2);
        lv_anim_set_time(&anim, 500); // 500ms闪烁间隔
        lv_anim_set_ready_cb(&anim, right_signal_anim_cb);
        lv_anim_start(&anim);
    }
    else
    {
        // 关闭右转向灯
        lv_obj_add_flag(ui_yxdon2, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_yxdoff1, LV_OBJ_FLAG_HIDDEN);
        is_right_signal_animating = false;
    }
}

// 右转向灯开关控制
void toggle_right_turn_signal(bool enable)
{
    // 如果开启右转向灯且双闪正在开启，先关闭双闪
    if (enable && hazard_lights_on) {
        toggle_hazard_lights(false);
    }

    if (!hazard_lights_on && enable == right_turn_signal_on)
        return;

    right_turn_signal_on = enable;

    if (enable && !is_right_signal_animating)
    {
        is_right_signal_animating = true;

        // 初始状态：点亮右转向灯
        lv_obj_add_flag(ui_yxdoff1, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_yxdon2, LV_OBJ_FLAG_HIDDEN);

        lv_anim_t anim;
        lv_anim_init(&anim);
        lv_anim_set_var(&anim, ui_yxdon2);
        lv_anim_set_time(&anim, 500);
        lv_anim_set_ready_cb(&anim, right_signal_anim_cb);
        lv_anim_start(&anim);
    }
    else if (!enable)
    {
        lv_obj_add_flag(ui_yxdon2, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_yxdoff1, LV_OBJ_FLAG_HIDDEN);
        is_right_signal_animating = false;
    }
}

// 双闪控制函数
void toggle_hazard_lights(bool enable)
{
    if (enable == hazard_lights_on)
        return;

    hazard_lights_on = enable;

    // 开启双闪时，先停止单独的转向灯动画
    if (enable) {
        if (left_turn_signal_on) {
            lv_anim_del(ui_zxdon2, NULL);
            left_turn_signal_on = false;
        }
        if (right_turn_signal_on) {
            lv_anim_del(ui_yxdon2, NULL);
            right_turn_signal_on = false;
        }
    }

    // 控制左右转向灯同时闪烁
    left_turn_signal_on = enable;
    right_turn_signal_on = enable;

    // 强制更新UI状态
    if (enable) {
        // 开启双闪时强制显示转向灯
        lv_obj_clear_flag(ui_zxdon2, LV_OBJ_FLAG_HIDDEN);
        lv_obj_add_flag(ui_zxdoff1, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_yxdon2, LV_OBJ_FLAG_HIDDEN);
        lv_obj_add_flag(ui_yxdoff1, LV_OBJ_FLAG_HIDDEN);
        
        // 启动闪烁动画
        lv_anim_t anim;
        lv_anim_init(&anim);
        lv_anim_set_var(&anim, ui_zxdon2);
        lv_anim_set_time(&anim, 500);
        lv_anim_set_ready_cb(&anim, left_signal_anim_cb);
        lv_anim_start(&anim);
        
        lv_anim_init(&anim);
        lv_anim_set_var(&anim, ui_yxdon2);
        lv_anim_set_time(&anim, 500);
        lv_anim_set_ready_cb(&anim, right_signal_anim_cb);
        lv_anim_start(&anim);
    } else {
        // 关闭双闪时强制隐藏转向灯
        lv_obj_add_flag(ui_zxdon2, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_zxdoff1, LV_OBJ_FLAG_HIDDEN);
        lv_obj_add_flag(ui_yxdon2, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_yxdoff1, LV_OBJ_FLAG_HIDDEN);
        
        // 停止所有动画
        lv_anim_del(ui_zxdon2, NULL);
        lv_anim_del(ui_yxdon2, NULL);
    }

    printf("双闪灯已%s\n", enable ? "开启" : "关闭");
}

void seechange(void)
{
    int change;
    char news[20];
    int current_angle;
    static int last_speed = -1; // 记录上次速度值

    if (new_speed != yb_speed)
    {
        printf("速度变化: %d -> %d\n", yb_speed, new_speed);

        // 更新速度值
        yb_speed = new_speed;

        // 更新速度显示
        char speed_str[10];
        snprintf(speed_str, sizeof(speed_str), "%d", new_speed);
        lv_label_set_text(ui_speedxs, speed_str);
        lv_label_set_text(ui_Label6, speed_str);
        lv_label_set_text(ui_Label1, speed_str);
        lv_label_set_text(ui_Label14, speed_str);

        // 调用改进后的指针动画函数
        update_speed_pointer(new_speed);

        printf("速度改变\n");
    }

    // 转速度变化处理
    if (new_rev_speed != yb_rev_speed)
    {
        printf("转速度变化: %d -> %d\n", yb_rev_speed, new_rev_speed);

        // 更新转速度值
        yb_rev_speed = new_rev_speed;

        // 更新转速度显示标签
        char rev_str[10];
        snprintf(rev_str, sizeof(rev_str), "%d", new_rev_speed);
        // 更新UI中所有相关标签...

        // 调用转速度指针动画
        update_revspeed_pointer(new_rev_speed);

        printf("转速度改变\n");
    }

    //  冷却液温度变化处理
    if (new_water_tem != yb_water_temp)
    {
        printf("冷却液温度变化: %d℃ -> %d℃\n", yb_water_temp, new_water_tem);

        // 确保温度在有效范围内
        new_water_tem = LV_CLAMP(0, new_water_tem, COOLANT_TEMP_RANGE);

        // 更新全局温度值
        yb_water_temp = new_water_tem;

        // 调用冷却液温度指针动画
        update_coolant_temp(new_water_tem);

        printf("冷却液温度改变\n");
    }

    if (new_tem != yb_tem)
    {
        yb_tem = new_tem;
        printf("温度改变\n");
    }
    if (new_zq_ty != yb_zq_ty)
    {
        yb_zq_ty = new_zq_ty;
        printf("左前胎压改变\n");
    }
    if (new_zh_ty != yb_zh_ty)
    {
        yb_zh_ty = new_zh_ty;
        printf("左后胎压改变\n");
    }
    if (new_yq_ty != yb_yq_ty)
    {
        yb_yq_ty = new_yq_ty;
        printf("右前胎压改变\n");
    }
    if (new_yh_ty != yb_yh_ty)
    {
        yb_yh_ty = new_yh_ty;
        printf("右后胎压改变\n");
    }
    if (new_zq_tem != yb_zq_tem)
    {
        yb_zq_tem = new_zq_tem;
        printf("左前温度改变\n");
    }
    if (new_zh_tem != yb_zh_tem)
    {
        yb_zh_tem = new_zh_tem;
        printf("左后温度改变\n");
    }
    if (new_yq_tem != yb_yq_tem)
    {
        yb_yq_tem = new_yq_tem;
        printf("右前温度改变\n");
    }
    if (new_yh_tem != yb_yh_tem)
    {
        yb_yh_tem = new_yh_tem;
        printf("右后温度改变\n");
    }
    if (new_xingshilic != yb_xingshilic)
    {
        yb_xingshilic = new_xingshilic;
        printf("行驶里程改变\n");
    }
    if (new_leijilic != yb_leijilic)
    {
        yb_leijilic = new_leijilic;
        printf("累计里程改变\n");
    }
    if (new_zonglic != yb_zonglic)
    {
        yb_zonglic = new_zonglic;
        printf("总里程改变\n");
    }
    if (new_xingshitime != yb_xstime)
    {
        yb_xstime = new_xingshitime;
        printf("行驶时间改变\n");
    }
    if (new_leijitime != yb_ljtime)
    {
        yb_ljtime = new_leijitime;
        printf("累计时间改变\n");
    }

    if (fabs(new_xingshiyouhao - yb_xingshiyouhao) > 0.01f)
    {
        printf("油耗变化: %.2f -> %.2f L/100km\n", yb_xingshiyouhao, new_xingshiyouhao);

        // 更新全局油耗值
        yb_xingshiyouhao = new_xingshiyouhao;

        // 调用油耗指针动画
        update_fuel_consumption(new_xingshiyouhao);
    }

    if (new_leijiyouhao != yb_leijiyouhao)
    {
        yb_leijiyouhao = new_leijiyouhao;
        printf("累计油量改变\n");
    }
    if (new_Pd != yb_Pd)
    {
        yb_Pd = new_Pd;
        printf("P档改变\n");
    }
    if (new_Rd != yb_Rd)
    {
        yb_Rd = new_Rd;
        printf("R档改变\n");
    }
    if (new_Nd != yb_Nd)
    {
        yb_Nd = new_Nd;
        printf("N档改变\n");
    }
    if (new_Dd != yb_Dd)
    {
        yb_Dd = new_Dd;
        printf("D档改变\n");
    }
    if (new_Sd != yb_Sd)
    {
        yb_Sd = new_Sd;
        printf("S档改变\n");
    }
    if (new_ptmode != yb_ptmode)
    {
        yb_ptmode = new_ptmode;
        printf("普通模式改变\n");
    }
    if (new_hbmode != yb_hbmode)
    {
        yb_hbmode = new_hbmode;
        printf("环保模式改变\n");
    }
    if (new_jsmode != yb_jsmode)
    {
        yb_jsmode = new_jsmode;
        printf("竞速模式改变\n");
    }
    if (new_yejianmode != yb_yejianmode)
    {
        yb_yejianmode = new_yejianmode;
        printf("夜间模式改变\n");
    }
    if (new_zhinengmode != yb_zhinengmode)
    {
        yb_zhinengmode = new_zhinengmode;
        printf("竞速模式改变\n");
    }
    if (new_zq_ty_jb != yb_zq_ty_jb)
    {
        yb_zq_ty_jb = new_zq_ty_jb;
        printf("左前胎压报警改变\n");
    }
    if (new_zh_ty_jb != yb_zh_ty_jb)
    {
        yb_zh_ty_jb = new_zh_ty_jb;
        printf("左后胎压报警改变\n");
    }
    if (new_yq_ty_jb != yb_yq_ty_jb)
    {
        yb_yq_ty_jb = new_yq_ty_jb;
        printf("右前胎压报警改变\n");
    }
    if (new_yh_ty_jb != yb_yh_ty_jb)
    {
        yb_yh_ty_jb = new_yh_ty_jb;
        printf("右后胎压报警改变\n");
    }

    if (new_zq_ldxh != yb_zq_ldxh)
    {
        yb_zq_ldxh = new_zq_ldxh;
        printf("左前雷达信号\n");
        if (yb_zq_ldxh)
        {
            lv_obj_clear_flag(ui_ldxh1on, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_ldxh1off, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_ldxh1on, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_ldxh1off, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    if (new_zh_ldxh != yb_zh_ldxh)
    {
        yb_carzitai_led = new_zh_ldxh;
        printf("左后雷达信号\n");
        if (yb_zh_ldxh)
        {
            lv_obj_clear_flag(ui_ldxh3on, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_ldxh3off, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_ldxh3on, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_ldxh3off, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    if (new_yq_ldxh != yb_yq_ldxh)
    {
        yb_yq_ldxh = new_yq_ldxh;
        printf("右前雷达信号\n");
        if (yb_yq_ldxh)
        {
            lv_obj_clear_flag(ui_ldxh2on, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_ldxh2off, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_ldxh2on, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_ldxh2off, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    if (new_yh_ldxh != yb_yh_ldxh)
    {
        yb_yh_ldxh = new_yh_ldxh;
        printf("右后雷达信号\n");
        if (yb_yh_ldxh)
        {
            lv_obj_clear_flag(ui_ldxh4on, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_ldxh4off, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_ldxh4on, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_ldxh4off, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    // 顶部指示灯
    if (new_cmzs_led != yb_cmzs_led)
    {
        yb_cmzs_led = new_cmzs_led;
        printf("车门打开指示灯改变\n");
        if (yb_cmzs_led)
        {
            lv_obj_clear_flag(ui_chemenon, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_chemenoff, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_chemenon, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_chemenoff, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    if (new_aqdjb_led != yb_aqdjb_led)
    {
        yb_aqdjb_led = new_aqdjb_led;
        printf("车安全带未系警报指示灯改变\n");
        if (yb_aqdjb_led)
        {
            lv_obj_clear_flag(ui_aqdjson, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_aqdjsoff, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_aqdjson, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_aqdjsoff, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    if (new_qwz_led != yb_qwz_led)
    {
        yb_qwz_led = new_qwz_led;
        printf("前位置灯指示灯改变\n");
        if (yb_qwz_led)
        {
            lv_obj_clear_flag(ui_qwzdon, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_qwzdoff, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_qwzdon, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_qwzdoff, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    if (new_hwz_led != yb_hwz_led)
    {
        yb_hwz_led = new_hwz_led;
        printf("后位置灯指示灯改变\n");
        if (yb_hwz_led)
        {
            lv_obj_clear_flag(ui_hwzon, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_hwzoff, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_hwzon, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_hwzoff, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    if (new_shache_led != yb_shache_led)
    {
        yb_shache_led = new_shache_led;
        printf("刹车指示灯改变\n");
        if (yb_shache_led)
        {
            lv_obj_clear_flag(ui_scon, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_scoff, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_scon, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_scoff, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    if (new_fadongji_led != yb_fadongji_led)
    {
        yb_fadongji_led = new_fadongji_led;
        printf("发动机指示灯改变\n");
        if (yb_fadongji_led)
        {
            lv_obj_clear_flag(ui_fdjon, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_fdjoff, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_fdjon, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_fdjoff, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    if (new_youya_led != yb_youya_led)
    {
        yb_youya_led = new_youya_led;
        printf("油压指示灯改变\n");
        if (yb_youya_led)
        {
            lv_obj_clear_flag(ui_yyon, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_yyoff, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_yyon, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_yyoff, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    if (new_shuangshan_led != yb_shuangshan_led)
    {
        yb_shuangshan_led = new_shuangshan_led;
        printf("双闪指示灯改变\n");
        if (yb_shuangshan_led)
        {
            lv_obj_clear_flag(ui_sson, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_ssoff, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_sson, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_ssoff, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    if (new_aqqn_led != yb_aqqn_led)
    {
        yb_aqqn_led = new_aqqn_led;
        printf("安全气囊打开指示灯改变\n");
        if (yb_aqqn_led)
        {
            lv_obj_clear_flag(ui_aqqnon, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_aqqnoff, LV_OBJ_FLAG_HIDDEN);  // 隐藏关状态
        }
        else
        {
            lv_obj_add_flag(ui_aqqnon, LV_OBJ_FLAG_HIDDEN);    // 隐藏关状态
            lv_obj_clear_flag(ui_aqqnoff, LV_OBJ_FLAG_HIDDEN); // 显示开状态
        }
    }

    // 近光灯指示灯更新
    if (new_jinguang_led != yb_jinguang_led)
    {
        yb_jinguang_led = new_jinguang_led;
        printf("近光灯指示灯改变\n");
        if (yb_jinguang_led)
        {
            lv_obj_clear_flag(ui_jgdon, LV_OBJ_FLAG_HIDDEN); // 显示开状态
            lv_obj_add_flag(ui_jgdoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_jgdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_jgdoff, LV_OBJ_FLAG_HIDDEN);
        }
    }

    // 远光灯指示灯更新
    if (new_yuanguang_led != yb_yuanguang_led)
    {
        yb_yuanguang_led = new_yuanguang_led;
        printf("远光灯指示灯改变\n");
        if (yb_yuanguang_led)
        {
            lv_obj_clear_flag(ui_ygdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_ygdoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_ygdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_ygdoff, LV_OBJ_FLAG_HIDDEN);
        }
    }

    if (new_qianwu_led != yb_qianwu_led)
    {
        yb_qianwu_led = new_qianwu_led;
        printf("前雾灯指示灯改变\n");
        if (yb_qianwu_led)
        {
            lv_obj_clear_flag(ui_qwdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_qwdoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_qwdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_qwdoff, LV_OBJ_FLAG_HIDDEN);
        }
    }

    if (new_houwu_led != yb_houwu_led)
    {
        yb_houwu_led = new_houwu_led;
        printf("后雾灯指示灯改变\n");
        if (yb_houwu_led)
        {
            lv_obj_clear_flag(ui_hwdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_hwdoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_hwdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_hwdoff, LV_OBJ_FLAG_HIDDEN);
        }
    }

    if (new_abs_led != yb_abs_led)
    {
        yb_abs_led = new_abs_led;
        printf("ABS指示灯改变\n");
        if (yb_abs_led)
        {
            lv_obj_clear_flag(ui_abson, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_absoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_abson, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_absoff, LV_OBJ_FLAG_HIDDEN);
        }
    }

    if (new_eco_led != yb_eco_led)
    {
        yb_eco_led = new_eco_led;
        printf("环保模式eco指示灯改变\n");
        if (yb_eco_led)
        {
            lv_obj_clear_flag(ui_ecoon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_ecooff, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_ecoon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_ecooff, LV_OBJ_FLAG_HIDDEN);
        }
    }

    if (new_zhidong_led != yb_zhidong_led)
    {
        yb_zhidong_led = new_zhidong_led;
        printf("驻车指示灯改变\n");
        if (yb_zhidong_led)
        {
            lv_obj_clear_flag(ui_zdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_zdoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_zdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_zdoff, LV_OBJ_FLAG_HIDDEN);
        }
    }

    if (new_aqdjb_led != yb_weixianjingbao_led)
    {
        yb_weixianjingbao_led = new_aqdjb_led;
        printf("危险警报指示灯改变\n");
        if (yb_weixianjingbao_led)
        {
            lv_obj_clear_flag(ui_jsdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_jsdoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_jsdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_jsdoff, LV_OBJ_FLAG_HIDDEN);
        }
    }

    if (new_qianchegai_led != yb_qianchegai_led)
    {
        yb_qianchegai_led = new_qianchegai_led;
        printf("前车盖打开指示灯改变\n");
        if (yb_qianchegai_led)
        {
            lv_obj_clear_flag(ui_qcgon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_qcgoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_qcgon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_qcgoff, LV_OBJ_FLAG_HIDDEN);
        }
    }

    if (new_houchegai_led != yb_houchegai_led)
    {
        yb_houchegai_led = new_houchegai_led;
        printf("后车盖打开指示灯改变\n");
        if (yb_houchegai_led)
        {
            lv_obj_clear_flag(ui_hcgon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_hcgoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
        {
            lv_obj_add_flag(ui_hcgon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_clear_flag(ui_hcgoff, LV_OBJ_FLAG_HIDDEN);
        }
    }

    if (new_yugua_led != yb_yugua_led)
    {
        yb_yugua_led = new_yugua_led;
        printf("雨刮指示灯改变\n");
        if (yb_yugua_led)
        {
            lv_obj_clear_flag(ui_yyon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_yyoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_yyon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_yyoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_xiansu_led != yb_xiansu_led)
    {
        yb_xiansu_led = new_xiansu_led;
        printf("限速指示灯改变\n");
        if (yb_xiansu_led)
        {
            lv_obj_clear_flag(ui_xson, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_xsoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_xson, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_xsoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_youliangjinggao_led != yb_youliangjinggao_led)
    {
        yb_youliangjinggao_led = new_youliangjinggao_led;
        printf("油量警告指示灯改变\n");
        if (yb_youliangjinggao_led)
        {
            lv_obj_clear_flag(ui_yldon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_yldoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_yldon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_yldoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_cardianchi_led != yb_cardianchi_led)
    {
        yb_cardianchi_led = new_cardianchi_led;
        printf("车辆电源指示灯改变\n");
        if (yb_cardianchi_led)
        {
            lv_obj_clear_flag(ui_cldcon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_cldcoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_cldcon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_cldcoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_carganying_led != yb_carganying_led)
    {
        yb_carganying_led = new_carganying_led;
        printf("车辆感应指示灯改变\n");
        if (yb_carganying_led)
        {
            lv_obj_clear_flag(ui_clgyon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_clgyoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_clgyon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_clgyoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_carxinhao_led != yb_carxinhao_led)
    {
        yb_carxinhao_led = new_carxinhao_led;
        printf("车辆信号指示灯改变\n");
        if (yb_carxinhao_led)
        {
            lv_obj_clear_flag(ui_xhon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_xhoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_xhon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_xhoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_carlengqueye_led != yb_carlengqueye_led)
    {
        yb_carlengqueye_led = new_carlengqueye_led;
        printf("车辆冷却液指示灯改变\n");
        if (yb_carlengqueye_led)
        {
            lv_obj_clear_flag(ui_lqyon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_lqyoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_lqyon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_lqyoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_carzitai_led != yb_carzitai_led)
    {
        yb_carzitai_led = new_carzitai_led;
        printf("车辆姿态指示灯改变\n");
        if (yb_carzitai_led)
        {
            lv_obj_clear_flag(ui_clzton, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_clztoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_clzton, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_clztoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_carlianwang_led != yb_carlianwang_led)
    {
        yb_carlianwang_led = new_carlianwang_led;
        printf("车联网指示灯改变\n");
        if (yb_carlianwang_led)
        {
            lv_obj_clear_flag(ui_clwon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_clwoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_clwon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_clwoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_zidongjiashi_led != yb_zidongjiashi_led)
    {
        yb_zidongjiashi_led = new_zidongjiashi_led;
        printf("自动驾驶指示灯改变\n");
        if (yb_zidongjiashi_led)
        {
            lv_obj_clear_flag(ui_zdjson, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_zdjsoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_zdjson, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_zdjsoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_chaosutixing_led != yb_chaosutixing_led)
    {
        yb_chaosutixing_led = new_chaosutixing_led;
        printf("超速提醒指示灯改变\n");
        if (yb_chaosutixing_led)
        {
            lv_obj_clear_flag(ui_cstxon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_cstxoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_cstxon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_cstxoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_daolufuzu_led != yb_daolufuzu_led)
    {
        yb_daolufuzu_led = new_daolufuzu_led;
        printf("道路辅助指示灯改变\n");
        if (yb_daolufuzu_led)
        {
            lv_obj_clear_flag(ui_dlfzon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_dlfzoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_dlfzon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_dlfzoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_taiyajinggao_led != yb_taiyajinggao_led)
    {
        yb_taiyajinggao_led = new_taiyajinggao_led;
        printf("胎压警告指示灯改变\n");
        if (yb_taiyajinggao_led)
        {
            lv_obj_clear_flag(ui_tyjgon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_tyjgoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_tyjgon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_tyjgoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_anquanjingbao_led != yb_anquanjingbao_led)
    {
        yb_anquanjingbao_led = new_anquanjingbao_led;
        printf("安全警报指示灯改变\n");
        if (yb_anquanjingbao_led)
        {
            lv_obj_clear_flag(ui_aqzsdon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_aqzsdoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_aqzsdon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_aqzsdoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_ld_system != yb_ld_system)
    {
        yb_ld_system = new_ld_system;
        printf("雷达系统改变\n");
        if (yb_ld_system)
        {
            lv_obj_clear_flag(ui_ldxhon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_ldxhoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_ldxhon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_ldxhoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_zny_system != yb_zny_system)
    {
        yb_zny_system = new_zny_system;
        printf("智能眼系统改变\n");
        if (yb_zny_system)
        {
            lv_obj_clear_flag(ui_znyon, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_znyoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_znyon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_znyoff, LV_OBJ_FLAG_HIDDEN);
    }

    if (new_yeshi_system != yb_yeshi_system)
    {
        yb_yeshi_system = new_yeshi_system;
        printf("夜视系统改变\n");
        if (yb_yeshi_system)
        {
            lv_obj_clear_flag(ui_ysxton, LV_OBJ_FLAG_HIDDEN);
            lv_obj_add_flag(ui_ysxtoff, LV_OBJ_FLAG_HIDDEN);
        }
        else
            lv_obj_add_flag(ui_ysxton, LV_OBJ_FLAG_HIDDEN);
        lv_obj_clear_flag(ui_ysxtoff, LV_OBJ_FLAG_HIDDEN);
    }

    usleep(5000);
}

int new_roller_index = -1;  // 初始化滚轮索引
Gear current_gear = GEAR_N; // 默认N档
const char *gear_names[] = {"P档", "R档", "N档", "D档", "S档"};
lv_obj_t *gear_ui_objects[5];

// 换挡处理函数
void handle_gear_change(Gear new_gear)
{
    // 更新全局档位状态
    current_gear = new_gear;

    // 更新UI显示
    for (int i = 0; i < 5; i++)
    {
        if (gear_ui_objects[i])
        {
            if (i == (int)new_gear)
            {
                lv_obj_clear_flag(gear_ui_objects[i], LV_OBJ_FLAG_HIDDEN);
            }
            else
            {
                lv_obj_add_flag(gear_ui_objects[i], LV_OBJ_FLAG_HIDDEN);
            }
        }
    }

    // 打印换挡信息
    printf("已切换到 %s\n", gear_names[(int)new_gear]);
}

bool update_tire_status(int pressure, int temperature,
                        lv_obj_t *ty_box, lv_obj_t *jg_box,
                        lv_obj_t *ty_label, lv_obj_t *temp_label,
                        lv_obj_t *ty_status_label, lv_obj_t *temp_status_label)
{
    // 检查胎压和胎温是否在正常范围内
    bool pressure_ok = (pressure >= NORMAL_PRESSURE_MIN && pressure <= NORMAL_PRESSURE_MAX);
    bool temp_ok = (temperature >= NORMAL_TEMP_MIN && temperature <= NORMAL_TEMP_MAX);
    bool is_normal = pressure_ok && temp_ok;

    // 更新胎压状态文本
    if (pressure_ok)
    {
        lv_label_set_text(ty_status_label, "胎压正常");
    }
    else if (pressure < NORMAL_PRESSURE_MIN)
    {
        lv_label_set_text(ty_status_label, "胎压过低");
    }
    else
    {
        lv_label_set_text(ty_status_label, "胎压过高");
    }

    // 更新胎温状态文本
    if (temp_ok)
    {
        lv_label_set_text(temp_status_label, "胎温正常");
    }
    else if (temperature < NORMAL_TEMP_MIN)
    {
        lv_label_set_text(temp_status_label, "胎温过低");
    }
    else
    {
        lv_label_set_text(temp_status_label, "胎温过高");
    }

    // 更新UI状态
    if (is_normal)
    {
        // 正常状态：显示ty_box，隐藏jg_box
        lv_obj_clear_flag(ty_box, LV_OBJ_FLAG_HIDDEN);
        lv_obj_add_flag(jg_box, LV_OBJ_FLAG_HIDDEN);

        // 更新胎压和胎温显示
        char buffer[20];
        snprintf(buffer, sizeof(buffer), "%dkPa", pressure);
        lv_label_set_text(ty_label, buffer);

        snprintf(buffer, sizeof(buffer), "%d°C", temperature);
        lv_label_set_text(temp_label, buffer);
    }
    else
    {
        // 异常状态：显示jg_box，隐藏ty_box
        lv_obj_clear_flag(jg_box, LV_OBJ_FLAG_HIDDEN);
        lv_obj_add_flag(ty_box, LV_OBJ_FLAG_HIDDEN);

        // 更新胎压和胎温显示
        char buffer[20];
        snprintf(buffer, sizeof(buffer), "%dkPa", pressure);
        lv_label_set_text(ty_label, buffer);

        snprintf(buffer, sizeof(buffer), "%d°C", temperature);
        lv_label_set_text(temp_label, buffer);
    }
}

void check_all_tires(void)
{
    // 更新每个轮胎状态
    update_tire_status(yb_zq_ty, yb_zq_tem, ui_tybox1, ui_jgbox1, ui_ty1, ui_tw1, ui_tyxs1, ui_twxs1);
    update_tire_status(yb_yq_ty, yb_yq_tem, ui_tybox2, ui_jgbox2, ui_ty2, ui_tw2, ui_tyxs2, ui_twxs2);
    update_tire_status(yb_zh_ty, yb_zh_tem, ui_tybox3, ui_jgbox3, ui_ty3, ui_tw3, ui_tyxs3, ui_twxs3);
    update_tire_status(yb_yh_ty, yb_yh_tem, ui_tybox4, ui_jgbox4, ui_ty4, ui_tw4, ui_tyxs4, ui_twxs4);

    // 检查所有轮胎状态
    bool all_normal = true;

    // 检查左前轮胎
    if (yb_zq_ty < NORMAL_PRESSURE_MIN || yb_zq_ty > NORMAL_PRESSURE_MAX ||
        yb_zq_tem < NORMAL_TEMP_MIN || yb_zq_tem > NORMAL_TEMP_MAX)
    {
        all_normal = false;
    }

    // 检查右前轮胎
    if (yb_yq_ty < NORMAL_PRESSURE_MIN || yb_yq_ty > NORMAL_PRESSURE_MAX ||
        yb_yq_tem < NORMAL_TEMP_MIN || yb_yq_tem > NORMAL_TEMP_MAX)
    {
        all_normal = false;
    }

    // 检查左后轮胎
    if (yb_zh_ty < NORMAL_PRESSURE_MIN || yb_zh_ty > NORMAL_PRESSURE_MAX ||
        yb_zh_tem < NORMAL_TEMP_MIN || yb_zh_tem > NORMAL_TEMP_MAX)
    {
        all_normal = false;
    }

    // 检查右后轮胎
    if (yb_yh_ty < NORMAL_PRESSURE_MIN || yb_yh_ty > NORMAL_PRESSURE_MAX ||
        yb_yh_tem < NORMAL_TEMP_MIN || yb_yh_tem > NORMAL_TEMP_MAX)
    {
        all_normal = false;
    }

    // 更新车辆整体状态图标
    if (all_normal)
    {
        // 所有轮胎正常：显示正常图标，隐藏警告图标
        lv_obj_clear_flag(ui_carjcon, LV_OBJ_FLAG_HIDDEN);
        lv_obj_add_flag(ui_carwton, LV_OBJ_FLAG_HIDDEN);
    }
    else
    {
        // 至少一个轮胎异常：显示警告图标，隐藏正常图标
        lv_obj_clear_flag(ui_carwton, LV_OBJ_FLAG_HIDDEN);
        lv_obj_add_flag(ui_carjcon, LV_OBJ_FLAG_HIDDEN);
    }
}

void *iu_main(void *arg)
{
    char input[50];
    while (1)
    {
        printf("\n======= 车载仪表控制台 =======\n");
        printf("设置速度: speed [0-240]\n");
        printf("设置转速度: rev [0-8000]\n");
        printf("换挡: p(驻车)/r(倒车)/n(空档)/d(前进)/s(运动)\n");
        printf("驾驶模式: 0(普通)/1(环保)/2(竞速)/3(夜间)/4(智能)\n");
        printf("指示灯控制: on/off [指示灯名称]\n");
        printf("左转向灯开启/关闭: on zuosan/off zuosan\n");
        printf("右转向灯开启/关闭: on yousan/off yousan\n");
        printf("双闪灯开启/关闭: on shuangshan/off shuangshan\n");
        printf("设置冷却液温度:coolant[e-120]\n");
        printf("请输入命令(youhao [0.0-1.0]): \n");
        printf("轮胎设置: tire [位置(1-4)] [胎压] [温度]\n");
        printf("退出: q 或 exit\n");
        printf("输入命令: ");
        if (fgets(input, sizeof(input), stdin) == NULL)
        {
            continue;
        }
        input[strcspn(input, "\n")] = '\0'; // 去除换行符

        // 左转向灯控制指令
        if (strcmp(input, "on zuosan") == 0)
        {
            printf("开启左转向灯\n");
            toggle_left_turn_signal(true);
            continue;
        }
        else if (strcmp(input, "off zuosan") == 0)
        {
            printf("关闭左转向灯\n");
            toggle_left_turn_signal(false);
            continue;
        }

        // 右转向灯控制指令
        if (strcmp(input, "on yousan") == 0)
        {
            printf("开启右转向灯\n");
            toggle_right_turn_signal(true);
            continue;
        }
        else if (strcmp(input, "off yousan") == 0)
        {
            printf("关闭右转向灯\n");
            toggle_right_turn_signal(false);
            continue;
        }

        else if (strcmp(input, "on shuangshan") == 0)
        {
            printf("开启双闪灯\n");
            toggle_hazard_lights(true);
        }
        else if (strcmp(input, "off shuangshan") == 0)
        {
            printf("关闭双闪灯\n");
            toggle_hazard_lights(false);
        }

        // 处理速度设置命令
        if (strncmp(input, "speed", 5) == 0)
        {
            // 解析命令，跳过"speed "，注意空格
            char *token = strtok(input + 6, " "); // input+5跳过"speed"和后面的一个空格
            if (token == NULL)
            {
                printf("命令格式错误！使用: speed [0-240]\n");
                continue;
            }

            int speed_value = atoi(token);
            if (speed_value < 0 || speed_value > 240)
            {
                printf("速度值必须在0~240之间！\n");
                continue;
            }

            new_speed = speed_value;
            printf("设置速度：%d km/h\n", speed_value);
        }

        // 处理转速度设置命令
        else if (strncmp(input, "rev", 3) == 0)
        {
            char *token = strtok(input + 4, " ");
            if (token == NULL)
            {
                printf("命令格式错误！使用: rev [0-8000]\n");
                continue;
            }

            int rev_value = atoi(token);
            if (rev_value < 0 || rev_value > 8000)
            {
                printf("转速度值必须在0~8000之间！\n");
                continue;
            }

            new_rev_speed = rev_value;
            printf("设置转速度：%d 转\n", rev_value);
        }

        // 油耗设置命令处理
        if (strncmp(input, "youhao", 6) == 0)
        {
            char *endptr;
            float consumption;

            // 提取数值部分
            char *num_start = input + 6;
            while (*num_start == ' ')
                num_start++; // 跳过空格

            // 转换为浮点数
            consumption = strtof(num_start, &endptr);

            // 输入有效性检查
            if (endptr == num_start)
            {
                printf("错误：请输入有效的数值\n");
            }
            else if (*endptr != '\0')
            {
                printf("错误：输入包含非法字符\n");
            }
            else if (consumption < 0.1f || consumption > 1.0f)
            {
                printf("错误：油耗值必须在0.0~1.0 L/100km之间\n");
            }
            else
            {
                // 设置新油耗值
                new_xingshiyouhao = consumption;
                printf("成功设置油耗为: %.2f L/100km\n", consumption);

                // 立即更新显示（可选）
                seechange();
            }
            continue;
        }

        // 处理冷却液温度设置命令
        else if (strncmp(input, "coolant", 7) == 0)
        {
            char *value_str = input + 7; // 跳过"coolant"

            // 跳过可能存在的空格
            while (*value_str == ' ')
                value_str++;

            // 检查是否有值
            if (*value_str == '\0')
            {
                printf("命令格式错误！使用: coolant [0-120]\n");
                continue;
            }

            // 尝试解析数值
            char *endptr;
            long temp_value = strtol(value_str, &endptr, 10);

            // 检查解析是否成功
            if (*endptr != '\0')
            {
                printf("无效的温度值: %s\n", value_str);
                printf("命令格式错误！使用: coolant [O-120]\n");
                continue;
            }

            // 检查温度范围
            if (temp_value < 0 || temp_value > 200)
            {
                printf("冷却液温度必须在0~120℃之间！\n");
                continue;
            }

            new_water_tem = (int)temp_value;
            printf("设置冷却液温度：%d ℃\n", new_water_tem);
        }

        // 处理轮胎设置命令
        if (strncmp(input, "tire", 4) == 0)
        {
            // 解析命令，跳过"tire "，注意空格
            char *token = strtok(input + 5, " "); // input+5跳过"tire"和后面的一个空格
            if (token == NULL)
            {
                printf("命令格式错误！使用: tire [1-4] [胎压] [温度]\n");
                continue;
            }

            // 解析轮胎位置
            int tire_pos = atoi(token);
            if (tire_pos < 1 || tire_pos > 4)
            {
                printf("轮胎位置错误！请输入1-4之间的数字\n");
                continue;
            }

            // 解析胎压
            token = strtok(NULL, " ");
            if (token == NULL)
            {
                printf("缺少胎压值！\n");
                continue;
            }
            int pressure = atoi(token);
            if (pressure <= 0)
            {
                printf("胎压必须大于0\n");
                continue;
            }

            // 解析温度
            token = strtok(NULL, " ");
            if (token == NULL)
            {
                printf("缺少温度值！\n");
                continue;
            }
            int temperature = atoi(token);
            if (temperature <= 0)
            {
                printf("温度必须大于0\n");
                continue;
            }

            // 更新对应轮胎的数据
            switch (tire_pos)
            {
            case 1: // 左前轮胎
                new_zq_ty = pressure;
                new_zq_tem = temperature;
                break;
            case 2: // 右前轮胎
                new_yq_ty = pressure;
                new_yq_tem = temperature;
                break;
            case 3: // 左后轮胎
                new_zh_ty = pressure;
                new_zh_tem = temperature;
                break;
            case 4: // 右后轮胎
                new_yh_ty = pressure;
                new_yh_tem = temperature;
                break;
            }
            printf("设置轮胎%d: 胎压=%dkPa, 温度=%d°C\n", tire_pos, pressure, temperature);

            // 立即更新轮胎状态显示
            check_all_tires();
        }

        // 处理换挡命令
        if (strlen(input) == 1)
        {
            char gear_char = input[0];
            switch (gear_char)
            {
            case 'p':
            case 'P':
                handle_gear_change(GEAR_P);
                break;
            case 'r':
            case 'R':
                handle_gear_change(GEAR_R);
                break;
            case 'n':
            case 'N':
                handle_gear_change(GEAR_N);
                break;
            case 'd':
            case 'D':
                handle_gear_change(GEAR_D);
                break;
            case 's':
            case 'S':
                handle_gear_change(GEAR_S);
                break;

            // 处理模式切换
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
                new_roller_index = input[0] - '0';
                printf("设置模式: %d\n", new_roller_index);
                break;

            case 'q':
            case 'Q':
                exit(0);
            default:
                printf("无效命令! 输入 'list' 查看帮助\n");
            }
        }

        // 处理指示灯控制命令
        else if (strlen(input) > 1)
        {
            char *command = strtok(input, " ");
            char *indicator = strtok(NULL, " ");

            if (command && indicator)
            {
                bool enable = false;
                if (strcmp(command, "on") == 0)
                {
                    enable = true;
                }
                else if (strcmp(command, "off") == 0)
                {
                    enable = false;
                }
                else
                {
                    printf("无效命令! 使用 'on' 或 'off'\n");
                    continue;
                }

                // 指示灯映射表
                struct IndicatorMap
                {
                    const char *name;
                    bool *var;
                } map[] = {
                    {"近光灯", &new_jinguang_led},
                    {"远光灯", &new_yuanguang_led},
                    {"车门打开指示灯", &new_cmzs_led},
                    {"安全带警报", &new_aqdjb_led},
                    {"刹车灯", &new_shache_led},
                    {"发动机灯", &new_fadongji_led},
                    {"双闪灯", &new_shuangshan_led},
                    {"前雾灯", &new_qianwu_led},
                    {"后雾灯", &new_houwu_led},
                    {"ABS灯", &new_abs_led},
                    {"ECO灯", &new_eco_led},
                    {"前位置灯", &new_qwz_led},
                    {"后位置灯", &new_hwz_led},
                    {"驻车", &new_zhidong_led},
                    {"危险警报指示灯", &new_weixianjingbao_led},
                    {"前车盖打开", &new_qianchegai_led},
                    {"后车盖打开", &new_houchegai_led},
                    {"雨刮指示灯", &new_yugua_led},
                    {"限速指示灯", &new_xiansu_led},
                    {"油量警告指示灯", &new_youliangjinggao_led},
                    {"车辆电源指示灯", &new_cardianchi_led},
                    {"车辆感应", &new_carganying_led},
                    {"车辆信号", &new_carxinhao_led},
                    {"车辆冷却液指示灯", &new_carlengqueye_led},
                    {"车辆姿态", &new_carzitai_led},
                    {"车联网", &new_carlianwang_led},
                    {"自动驾驶", &new_zidongjiashi_led},
                    {"超速提醒", &new_chaosutixing_led},
                    {"道路辅助", &new_daolufuzu_led},
                    {"胎压警告指示灯", &new_taiyajinggao_led},
                    {"安全警报指示灯", &new_anquanjingbao_led},
                    {"左前雷达信号", &new_zq_ldxh},
                    {"左后雷达信号", &new_zh_ldxh},
                    {"右前雷达信号", &new_yq_ldxh},
                    {"右后雷达信号", &new_yh_ldxh},
                    {"雷达系统", &new_ld_system},
                    {"智能眼系统", &new_zny_system},
                    {"夜视系统", &new_yeshi_system}

                };

                bool found = false;
                for (int i = 0; i < sizeof(map) / sizeof(map[0]); i++)
                {
                    if (strcmp(indicator, map[i].name) == 0)
                    {
                        *map[i].var = enable;
                        printf("已%s %s\n", enable ? "打开" : "关闭", map[i].name);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    printf("未找到指示灯: %s\n", indicator);
                    printf("可用指示灯: ");
                    for (int i = 0; i < sizeof(map) / sizeof(map[0]); i++)
                    {
                        printf("%s ", map[i].name);
                    }
                    printf("\n");
                }
            }
        }

        // 处理退出命令
        else if (strcmp(input, "exit") == 0)
        {
            exit(0);
        }
        else
        {
            printf("无效命令! 输入 'list' 查看帮助\n");
        }
    }
    return NULL;
}

/*自定义滴答时钟*/
uint32_t custom_tick_get(void)
{
    static uint64_t start_ms = 0;
    if (start_ms == 0)
    {
        struct timeval tv_start;
        gettimeofday(&tv_start, NULL);
        start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
    }
    struct timeval tv_now;
    gettimeofday(&tv_now, NULL);
    uint64_t now_ms;
    now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;

    uint32_t time_ms = now_ms - start_ms;
    return time_ms;
}

void init_input_output()
{
    // 配置显示接口
     fbdev_init();
    // // 初始化输入接口
     evdev_init();

    // sdl_init();

    // 输出接口
    static lv_color_t buf[DISP_BUF_SIZE];  // 显示缓冲区
    static lv_color_t buf1[DISP_BUF_SIZE]; // 显示缓冲区
    static lv_disp_draw_buf_t disp_buf;
    lv_disp_draw_buf_init(&disp_buf, buf, buf1, DISP_BUF_SIZE);

    // 设置显示缓冲区属性
    static lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv);
    disp_drv.draw_buf = &disp_buf;
    disp_drv.flush_cb = fbdev_flush;  //该代码是开发板进行测试显示使用的
    // disp_drv.flush_cb = sdl_display_flush; // 该代码是pc端进行测试显示使用的
    disp_drv.hor_res = 800;
    disp_drv.ver_res = 480;
    lv_disp_drv_register(&disp_drv);

    // 输入接口
    static lv_indev_drv_t indev_drv_1;
    lv_indev_drv_init(&indev_drv_1);          /*Basic initialization*/
    indev_drv_1.type = LV_INDEV_TYPE_POINTER; // 设置输入事件类型
    indev_drv_1.read_cb = evdev_read; //该代码是开发板进行测试显示使用的
    // indev_drv_1.read_cb = sdl_mouse_read; // 该代码是pc端进行测试显示使用的
    lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv_1);
}

int main(void)
{
    lv_init();
    // 初始化输入输出
    init_input_output();

    ui_init();

    // 初始化速度指针角度
    current_speed_angle = 0;
    lv_img_set_angle(ui_zhizhen1, -20);
    lv_img_set_pivot(ui_zhizhen1, 114, 21); // 设置旋转枢轴点

    // 初始化转速度指针
    current_rev_angle = 0;
    last_revspeed = 0;
    lv_img_set_angle(ui_zhizhen2, -30);
    lv_img_set_pivot(ui_zhizhen2, 114, 21); // 设置旋转枢轴点

    // 初始化冷却液温度指针
    current_coolant_angle = -450;
    last_coolant_temp = 0;
    lv_img_set_angle(ui_zhizhen3, -450);
    lv_img_set_pivot(ui_zhizhen3, 114, 21); // 设置旋转枢轴点

    // 初始化油耗指针
    init_fuel_pointer();

    // 初始化限位指针
    lv_img_set_angle(ui_xianzhi2, -75); // 设置最小角度限位

    // 创建档位UI对象映射
    gear_ui_objects[0] = ui_pdangon; // P档开状态对象
    gear_ui_objects[1] = ui_rdangon; // R档开状态对象
    gear_ui_objects[2] = ui_ndangon; // N档开状态对象
    gear_ui_objects[3] = ui_ddangon; // D档开状态对象
    gear_ui_objects[4] = ui_sdangon; // S档开状态对象

    // 设置初始档位(N档)
    handle_gear_change(GEAR_N);

    // 初始化后检查一次轮胎状态
    check_all_tires();

    // 创建模式切换线程
    pthread_t tid;
    pthread_create(&tid, NULL, iu_main, NULL);

    // 主循环
    while (1)
    {
        lv_timer_handler();

        // 检查并更新Roller显示
        if (new_roller_index >= 0)
        {
            lv_roller_set_selected(ui_Roller1, new_roller_index, LV_ANIM_ON);
            new_roller_index = -1; // 重置状态
        }

        // 检查并更新指示灯状态
        seechange();

        usleep(5000);
    }
    return 0;
}
